package com.itheima.demo7;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class MyInetAddressDemo1 {
    public static void main(String[] args) throws UnknownHostException {

        //获取InetAddress对象:表示ip的对象  即电脑的对象
        InetAddress address = InetAddress.getByName("LAPTOP-F9JMGQNK");
        System.out.println(address);

        //通过本机IP的InetAddress对象获取本机名字
        String hostName = address.getHostName();
        System.out.println(hostName);

        //通过本机IP的InetAddress对象获取本机端口
        String hostAddress = address.getHostAddress();
        System.out.println(hostAddress);

    }
}
